package com.xnx3.banmahuishou.userApplet.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xnx3.banmahuishou.core.entity.ScoreChangeRecord;
import com.xnx3.banmahuishou.userApplet.vo.ScoreChangeRecordListVO;
import com.xnx3.j2ee.controller.BaseController;
import com.xnx3.j2ee.service.SqlService;
import com.xnx3.j2ee.util.ActionLogUtil;
import com.xnx3.j2ee.vo.BaseVO;

/**
 * 积分变更记录相关
 * @author 王晓龙
 */
@Controller(value="BanmahuishouUserAppletScoreChangeRecordController")
@RequestMapping("/userApplet/scoreChangeRecord/")
public class ScoreChangeRecordController extends BaseController{
	@Resource
	private SqlService sqlService;
	
	/**
	 * 积分变更记录列表
	 * @author 王晓龙
	 */
	@RequestMapping(value="list.json",method = {RequestMethod.POST})
	@ResponseBody
	public ScoreChangeRecordListVO list(HttpServletRequest request) {
		ScoreChangeRecordListVO vo = new ScoreChangeRecordListVO();
		int userid = getUserId();
		if(getUserId() == 0) {
			vo.setBaseVO(BaseVO.FAILURE, "尚未登录");
			return vo;
		}
		//查询用户积分变更记录表
	    String sql = "SELECT * FROM laji_score_change_record WHERE userid = " + userid + " AND change_points != 0 ORDER BY add_time DESC";
	    //因只查询的一个表，所以可以将查询结果转化为实体类，用List接收。
	    List<ScoreChangeRecord> list = sqlService.findBySqlQuery(sql, ScoreChangeRecord.class);
	    
	    vo.setList(list);
		ActionLogUtil.insert(request, userid, "获取积分变更记录列表 :" + list.toString());
		return vo;
	}
}
